<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Skills
 *
 * @author Willie
 */
class Skills extends CI_Model{
    var $sql = "SELECT id FROM master_skill where SKILL_NAME=";// get the want id
    private $SKILL_TABLE_NAME="skills";
    private $USER_LOGIN_ID_VAR="USER_ID";
    private $MASTER_SKILL_TABLE="master_skill";
    
    function __construct() {
        parent::__construct();
    }
    function getAllSkills(){
        $sql = "SELECT id, SKILL_NAME FROM ".$this->MASTER_SKILL_TABLE;
        $rs = $this->db->query($sql);
        if($rs!=NULL){
            return $rs->result();
        }
        return NULL;
    }
    function getLearnId($learnKeyword=NULL){
      return $this->getIdByKeyword($learnKeyword);
    }
    function getTeachId($teachKeyword=NULL){
      return $this->getIdByKeyword($teachKeyword);
    }
    function getIdByKeyword($keyword){
        $retId=NULL;
           if($keyword==NULL || $keyword==""){
            return $retId;
        }
        $query=$this->sql."'".$keyword."';";
        $results=$this->db->query($query);
        foreach($results->result() as $r){
            $retId=$r->id;
            break;
        }
        return $retId;
    }
    
    function getSkillsById($uid){
        if($uid!=NULL && $uid!=""){
            $sql="SELECT s.id, SKILL_PROF,s.COMMENTS, YEARS_EXP,SKILL_RATING, SKILL_NAME,SKILL_TYPE FROM ";
            $sql.=$this->SKILL_TABLE_NAME." AS s LEFT JOIN ".$this->MASTER_SKILL_TABLE." AS ms ON "
                    . "s.SKILL_ID=ms.id WHERE ".$this->USER_LOGIN_ID_VAR." = $uid; ";
            
            $rs = $this->db->query($sql);
           
            if($rs!=NULL){
                return $rs->result();
            }
        }
        return NULL;// else return a null
    }
    function getNameById($searchId){
        $name=NULL;
        if($searchId==NULL || $searchId==""){
            return $name;
        }
        $sql = "SELECT SKILL_NAME FROM master_skill WHERE id=".$searchId;
        $results = $this->db->query($sql);
        foreach($results->result() as $r){
            $name=$r->SKILL_NAME;
            break;
        }
        return $name;
    }
    //put your code here
}
